package org.bim.view.drag.design.controller;


import org.bim.view.drag.design.api.req.VisualCategoryReq;
import org.bim.view.drag.design.dao.VisualCategoryMapper;
import org.bim.view.drag.design.entity.TVisualCategory;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.bim.view.drag.design.model.HttpResult;
import org.bim.view.drag.design.model.Page;
import org.bim.view.drag.design.util.PageUtil;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author bim-view
 * @date 2021/12/16 2:44 下午
 */
@Api
@AllArgsConstructor
@RestController
@RequestMapping("/category")
public class VisualCategoryController {
    private VisualCategoryMapper visualCategoryMapper;

    @GetMapping("detail")
    public HttpResult<TVisualCategory> detail(TVisualCategory req) {
        return HttpResult.success(visualCategoryMapper.selectOne(req));
    }

    @GetMapping("list")
    public HttpResult<List<TVisualCategory>> list(TVisualCategory req) {
        return HttpResult.success(visualCategoryMapper.select(req));
    }

    @GetMapping("page")
    public HttpResult<Page<TVisualCategory>> page(VisualCategoryReq req) {
        Page<TVisualCategory> page = PageUtil.doPage(req.toCondition(), () -> visualCategoryMapper.select(req.toEntity()));
        return HttpResult.success(page);
    }

    @PostMapping("save")
    public HttpResult<String> save(@RequestBody TVisualCategory form) {
        visualCategoryMapper.insertSelective(form);
        return HttpResult.success(form.getId());
    }

    @PostMapping("update")
    public HttpResult<String> update(@RequestBody TVisualCategory form) {
        visualCategoryMapper.updateByPrimaryKeySelective(form);
        return HttpResult.success(form.getId());
    }

    @PostMapping("remove")
    public HttpResult remove(@RequestParam String ids) {
        visualCategoryMapper.deleteByIds(ids);
        return HttpResult.success();
    }
}
